package com.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 1. TCP 服务器端
 */
public class SocketTCP01Client {

    public static void main(String[] args) throws IOException {
        // 1. 链接本机中 9999 端口的应用程序,如果链接成功，那么返回 socket对象
        System.out.println("InetAddress.getLocalHost()＝" +InetAddress.getLocalHost());
        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);
        System.out.println("客户端 socket = " + socket.getClass());

        // 2.连接服务器成功之后，发送数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("hello server".getBytes());
        System.out.println("客户端数据发送完毕.......");
        // 3.发送数据之后，必须关闭流，以及 socket
        outputStream.close();
        socket.close();
        System.out.println("客户端退出了........");

    }
}
